package com.chess;

import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

public class ChessServer {
	
	private ServerSocket serverSocket;
	private ChessServiceThread aloneThread;
	
	public ChessServer() {
		aloneThread = null;
	}
	
	public void start() throws IOException {
		serverSocket = new ServerSocket(5553);
		while(true) {
			Socket socket = serverSocket.accept();
			System.out.println("accept one client");
			
			if(aloneThread == null) {
				aloneThread = new ChessServiceThread(socket);
				//aloneThread.start();
			}
			else {
				ChessServiceThread t = new ChessServiceThread(socket);
				aloneThread.setPartnerThread(t);
				t.setPartnerThread(aloneThread);
				t.setPlaying(true);
				aloneThread.setPlaying(true);
				aloneThread.start();
				t.start();
				t.send("white");
				aloneThread.send("black");
				aloneThread = null;
			}
		}
	}
	
	
	
}
